<template>
    <div class="container committee-container">
        <system-nav name="组织关系详情" :showBack="true"></system-nav>
        <div class="inner">   
            <ul class="system-detail">
                <li>
                    <div>
                        <label>组织全称</label>
                        <span>{{ detail.deptName }}</span>
                    </div>
                    <div>
                        <label>组织级别</label>
                        <span>{{ detail.level | formatLevel }}</span>
                    </div>
                </li>
                <li>
                    <div>
                        <label>上级单位</label>
                        <span>{{ detail.fdeptName }}</span>
                    </div>
                    <div>
                        <label>书记</label>
                        <span>{{ detail.clerkName }}</span>
                    </div>
                </li>
            </ul>
            <Button class="btn-back" type="primary" @click="goBack" ghost>返回</Button>
        </div>              
    </div>
</template>

<script>
import SystemNav from '@/components/SystemNav'
import mixin from '@/mixins'
import { addPartyRest, getParentListRest, getPartyRest, editPartyRest } from '@/common/apis/system'
import { committeeLevelList } from '@/common/utils/const'

export default {
    name: 'committeeDetail',
    mixins: [mixin],
    components: {
        SystemNav
    },
    data() {
        return {
            levelList: committeeLevelList,
            fdeptList: [],
            detail: {
                deptName: '',
                level: 1,
                fdeptName: '',
                clerkName: ''
            }
        }
    },
    mounted() {
        this.id = this.$route.params.id
        this.initData()
    },
    methods: {
        initData() {
            getPartyRest(this.id).then(result => {
                this.committee = result.data.content
                const { deptName, level, fdeptName, clerkName } = this.committee
               
                this.detail = {
                    deptName,
                    level,
                    fdeptName,
                    clerkName
                }
            })
        },
        handleLevelChange(val, fid) {
            if (val !== 1) {
                getParentListRest(val).then(result => {
                    this.fdeptList = result.data.content
                    if(!fid) {
                        this.form.fid = this.fdeptList[0].id
                    }
                })
            } else {
                this.fdeptList = []
                this.form.fid = ''
            }
        }
    }
}
</script>